import { formTypeEnum } from '@/types/form'
// 抽屉控制变量显示
export const useDrawerFlag = (title: string = "") => {
    // 弹框标题
    const dialogTitle = ref(title)
    // 抽屉显示控制
    const dialogVisible = ref(false)
    // 关闭时是否检查确认框
    const closeConfirm = ref(true)
    // 确认抽屉关闭并取消提示
    const ConfirmDrawerVisible = () =>{
        closeConfirm.value = false
        dialogVisible.value = false
        // 异步还原弹框检测默认值
        setTimeout(()=>{
            closeConfirm.value = true
        },500)
    }

    return {
        dialogVisible,
        dialogTitle,
        closeConfirm,
        ConfirmDrawerVisible
    }
}
// 快速使用drawerHooks
export const useDrawerRef = () => {
    // 抽屉组件Ref
    const DrawerRef = ref()
    // 打开抽屉方法
    const openDrawer = (type: formTypeEnum, id?: number, data?: any) =>{
        if(!DrawerRef.value) {
            throw new Error('DrawerRef is not defined')
        }
        DrawerRef.value.open(type, id, data)
    }

    return { DrawerRef, openDrawer }
}